package com.group.Servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.group.pojo.GClass;
import com.group.pojo.GGroup;
import com.group.pojo.GStudent;
import com.group.pojo.GStudentPage;
import com.group.pojo.GWork;
 
/**
 * Servlet implementation class GroupInfoServlet
 */
@WebServlet("/GroupInfoServlet")
public class GroupInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public GroupInfoServlet() {
        super();
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取请求动作
		String action = request.getParameter("action");
		if(action.equals("info")) {
			String pageNo = request.getParameter("pageNo");
			if(pageNo == null || "".equals(pageNo)) {
				pageNo = "1";
			}
			GStudentPage pagination = new GStudentPage();
			pagination.setPageNo(Integer.parseInt(pageNo));
			GClass c = new GClass();
			//固定班级ID为130265
			String classID = "130265";
			int recordCount = c.getRecordCountByID(classID);
			int pageSize = pagination.getPageSize();
			pagination.setTotalPages((recordCount + pageSize - 1) / pageSize);
			List<GStudent> student_list = pagination.getPageData(classID);
			
			GGroup ggroup = new GGroup();
			List<GGroup> group_list = ggroup.getGGroupinfo();
			request.setAttribute("pagination", pagination);
			request.setAttribute("studentList", student_list);
			request.setAttribute("groupList", group_list);
			request.getRequestDispatcher("group.jsp").forward(request, response);
		}
		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
